package com.bdqn.controller;

import com.bdqn.pojo.SysDept;
import com.bdqn.service.SysDeptService;
import com.bdqn.service.impl.SysDeptServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//科室控制器
@RestController
@CrossOrigin
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    SysDeptService sysDeptService;
//    查询所有科室
    @GetMapping("getSysDept")
    public List<SysDept> getSysDept(){
        List<SysDept> list=sysDeptService.getSysDept();
        return list;
    }
    @GetMapping("getSysDeptFY")//int pageNum,int pageSize,int deptId,int subsectionType,int schedulingType,int scheduling_day
    public PageInfo<SysDept> getSysDeptFY(@RequestParam(value = "pageNum",defaultValue = "1",required = false) int pageNum,
                                      @RequestParam(value = "pageSize",defaultValue = "2",required = false) int pageSize,
                                      @RequestParam(value = "deptId",defaultValue = "0",required = false) int deptId,
                                      @RequestParam(value = "subsectionType",defaultValue = "0",required = false) int subsectionType,
                                      @RequestParam(value = "schedulingType",defaultValue = "0",required = false) int schedulingType,
                                          @RequestParam(value = "schedulingDay",defaultValue = "",required = false) String schedulingDay){
//        System.out.println(pageNum+"1");
//        System.out.println(pageSize+"1");
//        System.out.println(deptId+"1");
//        System.out.println(subsectionType+"1");
//        System.out.println(schedulingType+"1");
        PageInfo<SysDept> list=sysDeptService.getSysDeptFY(pageNum,pageSize,deptId,subsectionType,schedulingType,schedulingDay);
        return list;
    }
    @GetMapping("getPage")
    public PageInfo<SysDept> getPage(int pageNum,int pageSize,
            @RequestParam(value = "deptName",defaultValue = "",required = false)String deptName,
            @RequestParam(value = "status",defaultValue = "",required = false)int status){
        PageInfo<SysDept> list=sysDeptService.getPage(pageNum,pageSize,deptName,status);
        return list;
    }
    @GetMapping("addDept")
    public int addDept(@RequestParam(value = "deptName",defaultValue = "",required = false)String deptName,
                       @RequestParam(value = "deptNumber",defaultValue = "",required = false)String deptNumber,
                       @RequestParam(value = "deptLeader",defaultValue = "",required = false)String deptLeader,
                       @RequestParam(value = "leaderPhone   ",defaultValue = "",required = false)String leaderPhone,
                       @RequestParam(value = "orderNum",defaultValue = "",required = false)int orderNum,
                       @RequestParam(value = "status",defaultValue = "",required = false)int status,
                       @RequestParam(value = "userName",defaultValue = "",required = false)String userName){
        int row=sysDeptService.addDept(deptName,deptNumber,deptLeader,leaderPhone,orderNum
                ,status,userName);
        return row;
    }
    @GetMapping("setDept")
    public int setDept(@RequestParam(value = "deptName",defaultValue = "",required = false)String deptName,
                       @RequestParam(value = "deptNumber",defaultValue = "",required = false)String deptNumber,
                       @RequestParam(value = "deptLeader",defaultValue = "",required = false)String deptLeader,
                       @RequestParam(value = "leaderPhone   ",defaultValue = "",required = false)String leaderPhone,
                       @RequestParam(value = "orderNum",defaultValue = "",required = false)int orderNum,
                       @RequestParam(value = "status",defaultValue = "",required = false)int status,
                       @RequestParam(value = "userName",defaultValue = "",required = false)String userName,
                       @RequestParam(value = "deptId",defaultValue = "",required = false)String deptId){
        int row=sysDeptService.setDept(deptName,deptNumber,deptLeader,leaderPhone,orderNum
                ,status,userName,deptId);
        return row;
    }
    @GetMapping("delDept")
    public int delDept(String deptId){
        int row=sysDeptService.delDept(deptId);
        return row;
    }
}
